1057B - DDoS - CodeForces Solution


*special problem brute force *1400

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define pqueue priority_queue
#define int long long
using namespace std;
ll t,n,m,ans=0,x;
string soy;
pair<int,int> a[100005];
int pref[100005];
main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		a[i].fi=a[i-1].fi+x;
		a[i].sec=i;
	}
	for(int i=1;i<=n;i++){
		a[i].fi-=100*i;
	}
	sort(a,a+n+1);
	pref[0]=a[0].sec;
	for(int i=1;i<=n;i++){
		pref[i]=min(pref[i-1],a[i].sec);
	}
	int j=0;
	for(int i=1;i<=n;i++){
		while(j<n&&a[j+1].fi<a[i].fi) j++;
		if(a[i].fi>a[j].fi) ans=max(ans,a[i].sec-pref[j]);
	}
	cout<<ans<<endl;
}


Comments

Submit
0 Comments
More Questions

1661B - Getting Zero
1661A - Array Balancing
1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering
262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros
1519A - Red and Blue Beans
466A - Cheap Travel
659E - New Reform
1385B - Restore the Permutation by Merger
706A - Beru-taxi
686A - Free Ice Cream
1358D - The Best Vacation
1620B - Triangles on a Rectangle
999C - Alphabetic Removals
1634C - OKEA
1368C - Even Picture
1505F - Math
1473A - Replacing Elements